/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pl.milosnicy.miszcza.misiaela.mp3player.utils;

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.farng.mp3.AbstractMP3Tag;
import org.farng.mp3.id3.AbstractID3v2;
import org.farng.mp3.id3.ID3v1;
import org.jaudiotagger.audio.AudioFileIO;
import org.jaudiotagger.audio.exceptions.CannotReadException;
import org.jaudiotagger.audio.exceptions.InvalidAudioFrameException;
import org.jaudiotagger.audio.exceptions.ReadOnlyFileException;
import org.jaudiotagger.audio.mp3.MP3AudioHeader;
import org.jaudiotagger.audio.mp3.MP3File;
import org.jaudiotagger.tag.FieldKey;
import org.jaudiotagger.tag.TagException;
import org.jaudiotagger.tag.TagField;
import org.jaudiotagger.tag.id3.AbstractID3v2Tag;
import org.jaudiotagger.tag.id3.ID3v1Tag;
import org.jaudiotagger.tag.id3.ID3v24Tag;

/**
 *
 * @author Marcin.Wanke
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException, TagException, CannotReadException, ReadOnlyFileException, InvalidAudioFrameException, org.farng.mp3.TagException {
		 File file = new File("C:/michael/billie_jean.mp3");
//		MP3File f = (MP3File) AudioFileIO.read(file);
//		MP3AudioHeader audioHeader = (MP3AudioHeader) f.getAudioHeader();
//		audioHeader.getTrackLength();

//		String s = "";
//		ID3v1Tag tag31 = f.getID3v1Tag();
//		AbstractID3v2Tag tag32 = f.getID3v2Tag();
//		ID3v24Tag tag324 = f.getID3v2TagAsv24();
//		if(tag31 != null){
//			s += "Wykonawca: " + getField(tag31.getFields(FieldKey.ALBUM));
//		} else if(tag32 != null){
//			s += "Wykonawca: " + getField(tag32.getFields(FieldKey.ALBUM));
//		} else if(tag324 != null){
//			s += "Wykonawca: " + getField(tag324.getFields(FieldKey.ALBUM));
//		} else{
//			System.out.println("Zaden tag");
//		}
//		System.out.println(s);


		 org.farng.mp3.MP3File mp3File = new org.farng.mp3.MP3File(file);
		ID3v1 tag31 = mp3File.getID3v1Tag();
		AbstractID3v2 tag32 = mp3File.getID3v2Tag();
		AbstractMP3Tag tag = null;
		if(tag31 != null){
			tag = tag31;
		} else if(tag32 != null){
			tag = tag32;
		} else{
			System.out.println("Zaden tag");
		}

		if(tag != null){
			String s = "";
			s += "Wykonawca: " + tag.getLeadArtist() + "\n";
			s += "Tytuł: " + tag.getSongTitle() + "\n";
			s += "Album: " + tag.getAlbumTitle() + "\n";
			s += "Rok wydania: " + tag.getYearReleased() + "\n";
			s += "Autor/kompozytor: " + tag.getAuthorComposer() + "\n";
			s += "Wiodący artysta: " + tag.getLeadArtist() + "\n";
			s += "Typ: " + tag.getSongGenre() + "\n";
			s += "Pozycja w albumie: " + tag.getTrackNumberOnAlbum() + "\n";

			System.out.println(s);
		}

    }

//	public static String getField(List<TagField> tagFields){
//		String s = "";
//		for(TagField field : tagFields){
//			try {
//				s += new String(field.getRawContent()) + "\n";
//			} catch (UnsupportedEncodingException ex) {}
//		}
//		return s;
//	}
}
